#include <QLabel>
#include <QVBoxLayout>

#include "imageviewer.h"

namespace Jcr
{
class ImageViewPrivate
{
public:
    QLabel* label;
};

ImageViewer::ImageViewer(QWidget *parent) : QWidget(parent)
{
    d_ptr = new ImageViewPrivate;
    d_ptr->label = new QLabel(this);

    QVBoxLayout* layout = new QVBoxLayout;
    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(d_ptr->label);
    setLayout(layout);

    setWindowFlags(Qt::Tool);
    setWindowTitle(tr("Preview"));
}

ImageViewer::~ImageViewer()
{
    delete d_ptr;
}

ImageViewer* ImageViewer::instance()
{
    static ImageViewer iv;
    return &iv;
}

void ImageViewer::view(const QString& path)
{
    QPixmap pixmap(path);
    resize(pixmap.size());
    d_ptr->label->setPixmap(pixmap);
    show();
}

} // namespace jcr
